package com.cy.pj.sys.web.controller;

import com.cy.pj.common.pojo.JsonResult;
import com.cy.pj.common.util.PageUtil;
import com.cy.pj.sys.pojo.SysMenu;
import com.cy.pj.sys.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/menu")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    @GetMapping
    public JsonResult doFindMenus(){
        return new JsonResult(PageUtil.startPage().doSelectPageInfo(()->{
            sysMenuService.findMenus();
        }));
    }

    @GetMapping("/treeNodes")
    public JsonResult doFindMenuTreeNodes(){
        return new JsonResult(sysMenuService.findMenuTreeNodes());
    }

    @PostMapping
    public JsonResult doSaveMenu(@RequestBody SysMenu sysMenu){
        sysMenuService.saveMenu(sysMenu);
        return new JsonResult("save ok!!!");
    }

    @PutMapping
    public JsonResult doUpdateMenu(SysMenu sysMenu){
        sysMenuService.updateMenu(sysMenu);
        return new JsonResult("update ok!!!");
    }

}
